#!/usr/bin/php
<?php 
/*
 * @author: cosnis@gmail.com
 *
 * 文件上传工具
 */

$data = array(
	'fb.account.love' => array(
		'name'  => '比美用户登录',
		'host' 	=> '173.255.245.72',
		'port' 	=> '873',
		'dst' 	=> 'wwwhome/__account_common_love',
	),
	'fb.account.zjh' => array(
		'name'  => '扎金花用户登录',
		'host' 	=> '173.255.245.72',
		'port' 	=> '873',
		'dst' 	=> 'wwwhome/__account_common_zjh',
	),
);

$array = array();

if(count($argv) == 2 && $argv[1] == 'all') {
	$array = $data;
} else if(count($argv) > 1) {
	unset($argv[0]);
	foreach($argv as $x) {
		if(!isset($data[$x])) continue;
		$array[$x] = $data[$x];
	}
}

if(empty($array)) {
	
	print_r("\r\n\r\n" . '你可以输入以下内容上传到指定服务器, 也可以输入 all 全部上传' . "\r\n");
	foreach($data as $key => $d) {
		print_r($key . "\t" . $d['name'] . "\r\n");
	}
	exit;
}

$local_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;

`sudo chown -R nobody.nobody $local_path`;
`sudo chmod -R g+rwx $local_path`;

foreach($array as $k => $a) {
	echo $k . "\r\n";
	$ss = "rsync -avzP --password-file=/data/kevin/projects/www.password --exclude=.* --exclude=.svn --exclude=rsync_sh --exclude=_tmp {$local_path} www@{$a['host']}::{$a['dst']}";
	
	echo $ss;
	
	echo "\r\n\r\n";
	
	system($ss);
	
	echo "\r\n\r\n";
}
?>
